package com.xiaochong.tir.manager.enums;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 统一状态码
 */
public enum StatusEnum {

    OK(0, "操作成功"),
    PARAMS_ERROR(900, "参数错误"),
    OP_ERROR(800, "操作失败"),
    TOKEN_ERROR(501, "没有权限访问"),
    LOGIN_INVALID(504, "登录失效"),
    LOGOUT_SUCCESS(505, "退出成功"),
    SERVER_ERROR(400, "服务器错误");

    private int code;

    private String value;

    StatusEnum(int code, String value) {
        this.code = code;
        this.value = value;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    /**
     * 获取map集合枚举
     * @return
     */
    public static Map<Integer, String> toMap() {
        Map<Integer, String> map = new HashMap<Integer, String>();
        for (StatusEnum e : StatusEnum.values()) {
            map.put(e.getCode(), e.getValue());
        }
        return map;
    }

    /**
     * 获取list集合枚举
     * @return
     */
    public static List<StatusEnum> toList(){
        List<StatusEnum> list = new ArrayList<StatusEnum>();
        for (StatusEnum e : StatusEnum.values()){
            list.add(e);
        }
        return list;
    }

}
